<?php	include_once('../config/db.php');
		include_once('../functions/item.php');
if(!isset($_SESSION['e_logged_in'])) {
header('location:login.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../style.css" type="text/css"/>
<title>Online Reservation System</title>
</head>
<body>
<div id="header">
<div id="logo">
  <p>&nbsp;</p>
  <div id="apDiv1"><img src="../image/logo.png" alt="" width="500" height="100" /></div>
  <p>&nbsp;</p>
</div>
</div>
<div id="con-body">
<?php include 'navigation.php';?>
<div id="search">
<form id="form1" name="form1" method="post" action="track.php">
   <label for="textfield"></label>
   <input type="text" name="tracking" id="tracking" />
   <input name="button" type="submit" class="blue" id="button" value="Track Materials" />
 </form>
</div>
<p>List of laboratory materias</p>
<p>
  <?php 
  if(isset($_REQUEST['tracking'])){
  $track=$_POST['tracking'];
  $query=mysql_query("SELECT * FROM user LEFT JOIN borrow ON user.user_id = borrow.user_id LEFT JOIN item ON borrow.item_id = item.item_id WHERE tracking = '$track' GROUP BY tracking");
?>
<?php while($row=mysql_fetch_array($query)){?>
<form id="form2" name="form2" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
	<p>Tracking Number: <?php echo $row['tracking'];?></p>
	<input type="hidden" name="item_id" id="item_id" value="<?php echo $row['item_id']; ?>"/>
<p>ID number: <?php echo $row['user']; ?></p>
<p>Name: <?php echo $row['name'];?></p>
<p>Contact: <?php echo $row['contact'];?></p>
<p>Email <?php echo $row['email'];?>:</p>
<!--<p>Barrow date: From- <?php //echo $row['from_date']; ?>To- <?php //echo $row['to_date']; ?></p>
<p>Item Status: <?php //echo $row['item_status']; ?></p>-->

<p>Item/s Borrowed:</p>

<table width="1182" border="0">
  <tr>
    <td width="132" bgcolor="#99FFCC">Item Name</td>
    <td width="169" bgcolor="#99FFCC">Serial</td>
    <td width="203" bgcolor="#99FFCC">Requiring Subject</td>
    <td width="322" bgcolor="#99FFCC">Item Condition</td>
    <td width="109" bgcolor="#99FFCC">Date From</td>
    <td width="105" bgcolor="#99FFCC">Date To</td>
    <td width="112" bgcolor="#99FFCC">Date to return</td>
  </tr>
</table>
<?php 
if(isset($_REQUEST['tracking'])){
	$track=$_REQUEST['tracking'];
	$query1=mysql_query("SELECT * FROM borrow LEFT JOIN item ON item.item_id = borrow.item_id WHERE tracking = '$track'");
	$sno=array();
?>
<?php while($row1=mysql_fetch_array($query1)){?>
<table width="1181" border="0">
  <tr>
    <td width="132" bgcolor="#FFFF99"><?php echo $row1['item_name']?></td>
    <td width="171" bgcolor="#FFFF99"><?php echo $row1['item_serial']?></td>
    <td width="202" bgcolor="#FFFF99"><?php echo $row1['requiring_subject']?></td>
    <td width="324" bgcolor="#FFFF99"><?php echo $row1['item_condition']?>
<?php 
		if(isset($_REQUEST['update_button'])){
			$item_condition=$_REQUEST['item_condition'];
			$item_id=$_REQUEST['item_id'];	
			$sno=$_POST['sno'];
			$update_condition=mysql_query("UPDATE item SET item_condition='$item_condition' WHERE item_id='$item_id'") or die('ERROR:'.mysql_error());
		}
	?>
      <select name="item_condition" id="item_condition">
        <option>Good condition</option>
        <option>Not Working </option>
        <option>Damage</option>
      </select>
     <?php ?> 
      </td>
    <td width="108" bgcolor="#FFFF99"><?php echo $row1['from_date']?></td>
    <td width="104" bgcolor="#FFFF99"><?php echo $row1['to_date']?></td>
    <td width="110" bgcolor="#FFFF99"><?php echo $row1['pickup_time']?></td>
  </tr>
</table>
  <?php }}?>
  </br>
</p>

    <p>
      <label for="select"></label>
      <select name="item_status" id="item_status" value="">
        <option value="">------------------</option>
        <option value="">RETURNED</option>
        <option value="">CANCEL</option>
      </select>
    </p>
    <p>
      <input name="update_button" type="submit" id="update_button" value="Submit" />
    </p>
</form>
    <?php }}?>
    	<?php 
if(isset($_REQUEST['update_button'])){
		$item_id=$_REQUEST['item_id'];
		//$item_condition=$_REQUEST['item_condition'];
		//$item_status=$_REQUEST['item_status'];
		$update_kweri=mysql_query("UPDATE item SET item_status='AVAILABLE'") or die('ERROR:' .mysql_error());
		echo'<div id="success">Successfully Updated</div>';
}
?>
</div>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
</body>
</html>